package com.tjetc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tjetc.dao.FoodMapper;
import com.tjetc.entity.Food;
import com.tjetc.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 城市美食服务实现类
 */
@Service
@Transactional
public class FoodServiceImpl extends ServiceImpl<FoodMapper, Food> implements FoodService {

    @Autowired
    private FoodMapper foodMapper;

    @Override
    public List<Food> getFoodsByCityId(Long cityId) {
        return foodMapper.selectByCityId(cityId);
    }

    @Override
    public List<Food> getFoodsByCityIdAndCategory(Long cityId, String category) {
        return foodMapper.selectByCityIdAndCategory(cityId, category);
    }

    @Override
    public List<Food> getFoodsByNameLike(String name) {
        return foodMapper.selectByNameLike(name);
    }

    @Override
    public IPage<Food> getFoodPage(Page<Food> page, Long cityId, String category) {
        return foodMapper.selectFoodPage(page, cityId, category);
    }

    @Override
    public Food getFoodById(Long id) {
        return foodMapper.selectById(id);
    }

    @Override
    public boolean addFood(Food food) {
        return foodMapper.insert(food) > 0;
    }

    @Override
    public boolean updateFood(Food food) {
        return foodMapper.updateById(food) > 0;
    }

    @Override
    public boolean deleteFood(Long id) {
        return foodMapper.deleteById(id) > 0;
    }
}
